<?php

	define('SITE_ROOT', $_SERVER['DOCUMENT_ROOT'] . '/projet_mosquee/AMC/');
	// define('SITE_ROOT', $_SERVER['DOCUMENT_ROOT'] . '/inscriptions/');
include_once BDD_CLASS;

//Connexion au serveur Mysql
function connexion() {
	global $db;
	$db = new MySqlClass();
	$db->SqlHost = BDD_SERVER;
	$db->SqlUser = BDD_USER;
	$db->SqlPass = BDD_PASSWORD;
	$db->SqlBdd = DATA_BASE;
	$db->MysqlOpen();
	$db->MysqlQuery("SET NAMES 'UTF8'");
	
	return $db;
}

//Déconnexion de la base de données
function deconnexion() {
	global $db;
	$db->MysqlClose();
}

//Date PHP YYYY-MM-DD -> DD/MM/YYYY
function datePHP($d) {
    return substr($d,-2)."/".substr($d,5,2)."/".substr($d,0,4);
}

//Date Mysql DD/MM/YYYY -> YYYY-MM-DD
function dateMysql($d) {
    return substr($d,-4)."-".substr($d,3,2)."-".substr($d,0,2);
}

function getJour($j) {
	$jours = array ("Lundi", "Mardi", "Mercredi", "Jeudi", "Vendredi", "Samedi", "Dimanche");
	return $jours[(int)$j-1];
	
}

function getMois($m) {
	$mois = array ("Janvier", "Février", "Mars", "Avril", "Mai", "Juin", "Juillet", "Août", "Septembre", "Octobre", "Novembre", "Décembre");
	return $mois[(int)$m-1];
}

//Affiche le sous-menu
function affiche_menus($affiche_sous_menu = 1) {
	include "configuration.php";
	foreach ($conf["menus"] as $menu) {
		foreach ($menu['index'] as $k => $v) {
			echo "<li class='fullwidth' ><a href='$k.php'"; 
			if (count($menu) > 1) echo " class='drop'"; 
			echo ">" . $v . "</a>";
			break;
		} 
			$iteration = 0;
			if (count($menu) > 1 && $affiche_sous_menu == 1) {
				echo '<div class="dropdown_fullwidth first_fullwidth">';
					echo '<div class="col_2">';
						echo "<ul>";
			}
			if ($affiche_sous_menu == 1) {
				foreach ($menu as $lien => $smenu) {
					$parents[$lien] = $menu["index"];
					if ($iteration++ == 0) continue;
					echo "<li><a href='$lien.php'>" . $smenu . "</a></li>";
				}
			}
			if (count($menu) > 1) {
						echo "</ul>";
					echo "</div>";
				echo "</div>";
			}
		echo "</li>";
	}
}

//Redirection
function redirect($page, $timeout = 0) {
    echo "<script language='Javascript'>
    setTimeout('opening()',$timeout);
    function opening() {
        document.location.replace('$page');
    }
    </script>";
}

//Envoi de mail
function send_mail ($from, $subject, $infos = array()) {
	ini_set('SMTP',$conf["smtp_server"]); 
	$headers = 'MIME-Version: 1.0' . "\r\n";
	$headers.= 'Content-type: text/html; charset=utf-8' . "\r\n";
	$headers.= 'Content-Transfer-Encoding: 8bit' . "\r\n"; 
	$headers.= 'From:'. $from  . " \r\n";
	$message = "";
	foreach ($infos as $titre => $info) {
		$message.= $titre . " : " . $info . "<br>";
	}
	@mail($conf["email"], $subject, $message, $headers); 
}

//Début d'un article 
function start_article($titre = "", $style="text-align:justify") {
	?>
	<div class="content">
		<section class="grid-holder">
			<section class="grid">
				<div class="heading-holder">
					<h3 class="content-heading"><span><em class="h-left"></em><span class="inner-heading"><?php echo $titre; ?></span><em class="h-right"></em></span></h3>
				</div>
				<article class="column" style="<?php echo $style; ?>">
	<?php
}

//Fin d'un article
function end_article() {
	?>
				</article>
			</section>
		</section>
	</div>
	<?php 
}
?>